import { ApiResponse, ChannelItem } from "@/types/data"
import { ChannelAction, RootThunkAction } from "@/types/store"
import request from "@/utils/request"

// 获取频道列表
export const getChannels = (): RootThunkAction => {
  return async (dispatch) => {
    const { data: { data: { channels } } } = await request.get<ApiResponse<{
      channels: ChannelItem[]
    }>>('/channels')
    dispatch({
      type: 'CHANNEL_SAVE',
      payload: channels
    })
  }
}

export const changeActive = (id: number): ChannelAction => ({
  type: 'CHANNEL_ACTIVE',
  payload: id
})